package com.fu.core.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 付龙江
 * @date 2022/1/27 21:43
 */
public class RegexUtil {

	/**
	 * 手机号正则校验
	 * @param phone
	 * @return
	 */
	public static boolean isPhoneNumber(String phone){
		boolean bool =  phone.matches("^1(3\\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$");
		return bool;
	}

	/**
	 * 时间格式正则校验（yyyy-MM-dd HH:mm:ss）
	 * @param time
	 * @return
	 */
	public static boolean isTimestampFormat(String time) {
		String regex = "^((\\d{2}(([02468][048])|([13579][26]))[\\-/\\s]?((((0?[13578])|(1[02]))[\\-/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-/\\s]?((((0?[13578])|(1[02]))[\\-/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([0-1][0-9])|(2[0-3])):([0-5][0-9])((\\s)|(:([0-5][0-9])))([AM|PM|am|pm]{0})))?$";

		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(time);
		return matcher.matches();
	}
}
